<%@ page language="java" import="com.alibaba.fastjson.JSONObject" pageEncoding="UTF-8" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.soa.workflow.request.RequestInfo" %>
<%@ page import="weaver.soa.workflow.request.RequestService" %>
<%--用款台账点击批量提交更新状态并提交流程--%>
<%
    JSONObject dataJson = new JSONObject();
    try {
        RecordSet rs = new RecordSet();
        rs.executeQuery("select a.id,a.fklc from (select id,fklc from uf_ybyktz where sfyzfwc=0 and nvl(lctjzt,1)=1 group by fklc,id) a," +
                "workflow_requestbase b where a.fklc=b.requestid and b.currentnodetype<3");
        int counts = rs.getCounts();
        int succcount = 0;
        while (rs.next()) {
            String fklc = Util.null2String(rs.getString("fklc"));
            String id = Util.null2String(rs.getString("id"));
            boolean status = autoSubmit(fklc);
            if (status) {
                rs.executeUpdate("update uf_ybyktz set lctjzt=0 where id=?", id);
                succcount++;
            }

        }
        dataJson.put("counts", counts);
        dataJson.put("succcount", succcount);
        dataJson.put("failcount", counts - succcount);
    } catch (Exception e) {
        dataJson.put("counts", 0);
        dataJson.put("succcount", 0);
        dataJson.put("failcount", 0);
        e.printStackTrace();
    }
    out.print(dataJson.toJSONString());
%>
<%!

    public static boolean autoSubmit(String requestid) {
        RecordSet rs = new RecordSet();
        rs.executeQuery("select distinct userid,usertype,agenttype,agentorbyagentid from workflow_currentoperator\n" +
                " where (isremark in ('0','1','5','7','8','9') or (isremark='4' and viewtype=0))  and requestid = ?", requestid);
        rs.next();
        int operator = Util.getIntValue(rs.getString("userid"));
        RequestService server = new RequestService();
        RequestInfo requestInfo = server.getRequest(Integer.parseInt(requestid));
        return new RequestService().nextNodeBySubmit(requestInfo, Integer.parseInt(requestid), operator, "");
    }
%>



